const http = require('http')
const Router = require('./router/index')
const methods = require('methods')

function App(){
    this._router = new Router()
}
methods.forEach(method => {
    // 3.handlers 处理
    App.prototype[method] = function(path,...handlers) {
        this._router[method](path,handlers)
    }
})

App.prototype.listen = function() {
    const server = http.createServer((req, res) => {
        this._router.handle(req,res)
    })
    server.listen(...arguments)
}
// 1.新增 use 方法
App.prototype.use = function(path,...handlers){
    this._router.use(path,handlers)
}
module.exports = App
